<?php
class Form_RequestDonation extends App_Dojo_Form
{    	
	public $_selectStates = array();
    
    public $_selectEthnicity = array();
	
	public $_noDecorators = array(
    	'DijitElement',
	);
	
	public $_divfilesDecorators = array(		
		array(array('dd' => 'HtmlTag'), array('tag' => 'div', 'class' => 'field', 'id' => 'Files')),
		array('HtmlTag', array('tag' => 'dd')),		
		array('Label', array('tag' => 'dt')),
	);
	
	public $_divuploadbtnDecorators = array(			
		array('Label',array('separator' => '', )),
		array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div', 'class' => 'uploadBtn btn', 'id' => 'btnF')),
		array(array('dd' => 'HtmlTag'), array('tag' => 'dd')),		
	);
	
	public function init()
    {
        $this->setName('formRequestDonation');
        
        $this->setMethod('post');
        
       	$this->setDecorators(array(    
			'FormElements',    
			array(
				'HtmlTag', 
				array(
					'tag' => 'dl',
					'class' => 'form normal'
					)
			),    
			'DijitForm',
		));
				
        $this->addElement(
            'FilteringSelect',
            'gender',
            array(
                'label' 			=> 'Gender',
            	'autocomplete'		=> true,
                'multiOptions' 		=> array( 'M' => 'Male', 'F' => 'Female'),            	
            )
        );
        
        $this->addElement(    
        	'NumberTextBox',    
        	'age',    
        	array(        
        		'label'          => 'Age',        
        		'required'       => true,   
        		'promptMessage'	 => 'Enter your age.',     
        		'invalidMessage' => 'Invalid age.',        
        		'places'         => 0,
        		'constraints'    => array('min'    => 1,'max'    => 150,
        	    ),    
        	)
        );
           
       	$ethnicities = new Ethnicities();  
        $this->_selectEthnicity = $ethnicities->getDataDropDown();
        $this->addElement(
            'FilteringSelect',
            'ethnicity',
            array(
                'label' 			=> 'Ethnicity',
	           	'autocomplete'		=> true,
                'multiOptions' 		=> $this->_selectEthnicity,            	
            )
        );
        
        $this->addElement(
        	'ValidationTextBox', 
        	'title', 
        	array(
	            'label'          	=> 'Project title',
	            'required'       	=> true,
        		'promptMessage'		=> 'Enter project title.',
	            'invalidMessage' 	=> 'Please type project title.',
        		'maxlength'      	=> 100,
        		'trim'      		=> true,
	            'validators' 		=> array(
					'NotEmpty', 
        			array('StringLength', true, array(2, 100))
            	),
        	)
        );
        
        $this->addElement ( 
			'Textarea', 
			'description', 
			array (
				'label' 			=> 'Project description', 
				'promptMessage'		=> 'Enter project description.',
	            'invalidMessage' 	=> 'Please type project description.',
				'required' 			=> true,
				'style' 			=> 'width: 182px;', 
	            'maxlength'      	=> 500, 
			) 
		);
		
		$this->addElement(
        	'ValidationTextBox', 
        	'city', 
        	array(
	            'label'          	=> 'City',
	            'required'       	=> true,
        		'promptMessage'		=> 'Enter city.',
	            'invalidMessage' 	=> 'Please type city.',
        		'maxlength'      	=> 100,
        		'trim'      		=> true,
	            'validators' 		=> array(
					'NotEmpty', 
        			array('StringLength', true, array(2, 100))
            	),
        	)
        );
                
        $states = new States();
        $this->_selectStates = $states->getDataDropDown();
        $this->addElement(
            'FilteringSelect',
            'id_state',
            array(
                'label' 			=> 'State',
            	'autocomplete'		=> true,
                'multiOptions' 		=> $this->_selectStates,            	
            )
        );
        
        $this->addElement(
        	'ValidationTextBox', 
        	'address', 
        	array(
	            'label'          	=> 'Address',
	            'required'       	=> true,
        		'promptMessage'		=> 'Enter the address.',
	            'invalidMessage' 	=> 'Please type the address.',
        		'maxlength'      	=> 100,
        		'trim'      		=> true,
	            'validators' 		=> array(
					'NotEmpty', 
        			array('StringLength', true, array(2, 100))
            	),
        	)
        );
        
        $this->addElement(    
			'Hidden',    
			'files',    
			array(
				'label'     	=> 'Photos',
				'decorators' 	=> $this->_divfilesDecorators,
			)
		);
		
		$this->addElement(    
			'Hidden',    
			'selectbtn',    
			array(
				'label'     	=> 'Select Image',
				'decorators' 	=> $this->_divuploadbtnDecorators,
			)
		);
        
        $this->addElement ( 
			'ValidationTextBox', 
			'video_url', 
			array (
				'required' 			=> false, 
				'label' 			=> 'Video URL', 
				'regExp' 			=> '^http[s]?://([a-zA-Z0-9\-]+\.)*([a-zA-Z]{3,61}|[a-zA-Z]{1,}\.[a-zA-Z]{2})/.*$',
				'promptMessage'		=> 'Enter video URL.', 
				'invalidMessage' 	=> 'Please provide a valid Video URL.', 
				'filters' 			=> array ('StringTrim', 'StringToLower' ), 
				'maxlength'      	=> 100,
				'style'				=> 'width: 182px',
				'validators' 		=> array (
					'NotEmpty', 
					array ('StringLength', true, array (6, 100 )),
				) 
			)
		);
		
		$this->addElement(
        	'CurrencyTextBox', 
        	'funds', 
        	array(
	            'label'          	=> 'Funds request (USD)',
	            'required'       	=> true,
        		'promptMessage'		=> 'Enter funds request (in USD).',
	            'invalidMessage' 	=> 'Invalid amount.  Cents are required.',        		
        		'currency'			=> 'USD'            
        	)
        );
        
        $this->addElement ( 
			'DateTextBox', 
			'date_funds', 
			array (
				'label' 		=> 'Date funds needed',
				'promptMessage'	=> 'Select a date please.', 
				'required' 		=> true,
				'constraints'	=>	array(
					'datePattern'	=> 	'MM/dd/yyyy',
				),
			) 
		);
		
		$this->addElement(    
			'Hidden',    
			'filename',    
			array(        
				'value' 		=> '0',    
				'decorators' 	=> $this->_noDecorators,
			)
		);
		
		$this->addElement(
        	'Button', 
        	'submitButton',
            array(
                'type'   	 => 'submit',
            	'required'   => false,
                'ignore'     => true,
                'label'      => 'Submit',
            	'iconClass'  => 'myIcons okIcon',
                'style' 		=> 'margin-top: 10px;',  
            )
        );
    }	
}